{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">同城配送设置</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"
                   data-auth-add="{:$auth->check('banner.banner/add')}"
                   data-auth-edit="{:$auth->check('banner.banner/edit')}"
                   data-auth-delete="{:$auth->check('banner.banner/del')}"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="picTpl">
    <img style="max-width:100px; max-height:60px;" src="{{d.img}}" data-image="{{d.title}}">
</script>

<script type="text/html" id="barTool">
    {if $userInfo['roleid']==1}
    <a class="layui-btn layui-btn-xs" data-open='{:url("edit")}?id={{ d.id }}' data-title="编辑内容"
       data-full="true">编辑</a>
    <a href='{:url("del",["catid"=>$catid])}?ids={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
    {/if}
</script>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" data-href='{:url("setstate")}?id={{d.id}}' value="{{d.id}}"
           lay-skin="switch"
           lay-text="显示|隐藏" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    layui.use('yznTable', function () {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: '{:url("add")}?yfcm_id={$yfcm_id}',
            edit_url: '{:url("edit")}',
            delete_url: '{:url("del")}',
        };
        var proviec = {:json_encode($proviec)};

        table.render({
            init: init,
            toolbar: ['refresh', 'add'],
            url: '{:url("index")}?yfcm_id={$yfcm_id}',
            search: true,
            cols: [
                [
                    //名称 水票背景图 所属商品分类 所属商品

                    {field: 'id', width: '5%', title: 'ID'},
                    {field: 'province', width: '40%',align: "center",  title: '一级区域',    selectList: proviec},
                    {field: 'city', width: '40%',align: "center",  title: '二级区域', selectList: {}},
                    // {field: 'mj', align: "center", width: '15%', title: '满减包邮',search: false},
                    // {field: 'fee', align: "center", width: '15%', title: '邮费',search: false},
                    {fixed: 'right',align: "center",  width: '20%', title: '操作', toolbar: '#barTool'}
                ]
            ],
            page: {}
        });

        yznTable.bindevent();
        selectElement = document.getElementById('c-province');
        selectElement.setAttribute("lay-filter", "c-province");
        form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);
    });
    function form1(){
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate')}",//提交URL
                    data: {'id':data.value},//提交的数据
                    success: function(result){
                        if(result.code == 200){
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function(i, val){
                                str += '<option value='+val.id+'>'+val.name+'</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function() {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }
</script>
{/block}